package com.javaweb.controller;

import com.javaweb.service.dto.UserDto;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.Email;
import javax.validation.constraints.Max;
import javax.validation.constraints.NotBlank;

/**
 * @desc:
 * @author: Ping
 * @date: 2024/11/9 14:09
 */
@Controller
@RequestMapping("param-validate")
@Slf4j
public class ParamValidateController {

    @PostMapping("/simple")
    @Validated
    public String processSimpleParam(@NotBlank @RequestParam String username,
                                     @Email @RequestParam  String email,
                                     @NotBlank @RequestParam  String password,
                                     @DecimalMax("100") @RequestParam int age) {
        log.info("username: {}, password: {}", username, password) ;
        return "success";
    }

    @PostMapping("/object")
    public String processObjectParam(@Validated UserDto userDto) {

        log.info("username: {}, password: {}", userDto.getUsername(), userDto.getPassword()) ;
        return "success";
    }


}
